<template>
  <div class="panel-group">
    <a-row :gutter="24">
      <a-col :sm="12" :md="6" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('revenue')">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="clipboard" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            营收额
          </div>
          <count-to :start-val="0" :end-val="countData.revenue" :duration="2600" class="card-panel-num" :decimals = "2"/>
            <a-statistic
              :value="countData.revPercent"
              :precision="2"
              suffix="%"
              :value-style="countData.revStatus == 1 ? statisticColor.down:statisticColor.up"
              style="margin-right: 50px"
            >
            <template #prefix>
              <a-icon type="arrow-up" />
            </template>
          </a-statistic>
        </div>
      </div>
    </a-col>
      <a-col :sm="12" :md="6" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('payPerecnt')">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="clipboard" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            支出额
          </div>
          <count-to :start-val="0" :end-val="countData.pay" :duration="2600" class="card-panel-num" :decimals = "2"/>
            <a-statistic
              :value="countData.payPerecnt"
              :precision="2"
              suffix="%"
              :value-style="countData.payStatus == 1 ? statisticColor.down:statisticColor.up"
              style="margin-right: 50px"
            >
            <template #prefix>
              <a-icon type="arrow-up" />
            </template>
          </a-statistic>
        </div>
      </div>
    </a-col>
      <a-col :sm="12" :md="6" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('recPercent')">
          <div class="card-panel-icon-wrapper icon-people">
            <svg-icon icon-class="clipboard" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              应收款
            </div>
            <count-to :start-val="0" :end-val="countData.receivable" :duration="2600" class="card-panel-num" :decimals = "2"/>
              <a-statistic
                :value="countData.recPercent"
                :precision="2"
                suffix="%"
                :value-style="countData.recStatus == 1 ? statisticColor.down:statisticColor.up"
                style="margin-right: 50px"
              >
              <template #prefix>
                <a-icon type="arrow-up" />
              </template>
            </a-statistic>
            </div>
        </div>
      </a-col>
      <a-col :sm="12" :md="6" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('payablePercent')">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="clipboard" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            应付款
          </div>
          <count-to :start-val="0" :end-val="countData.payable" :duration="2600" class="card-panel-num" :decimals = "2"/>
            <a-statistic
              :value="countData.payablePercent"
              :precision="2"
              suffix="%"
              :value-style="countData.payableStatus == 1 ? statisticColor.down:statisticColor.up"
              style="margin-right: 50px"
            >
            <template #prefix>
              <a-icon type="arrow-up" />
            </template>
          </a-statistic>
        </div>
      </div>
    </a-col>
    </a-row>
  </div>

</template>

<script>
import CountTo from 'vue-count-to'
import request from '@/utils/request'
import { getAction, postActionByJson, postActionByQueryString } from "@/api/manage";


export default {
  components: {
    CountTo
  },
  data () {
    return {
      statisticColor: {
          up : { color: '#cf1322' },
          down: { color: '#3f8600' }
      },
      countData: {supTotal: 0,proTotal: 0}
    }
  },

  created () {
    this.loadData("year")
  },
  methods: {
    handleSetLineChartData(type) {
      this.$emit('handleSetLineChartData', type)
    },
    loadData(condition) {
        console.info(condition)
      request.get("/sysIndex/businessStatistics?condition=" + condition)
      .then(resp => {
        this.countData = resp.data
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 150px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      margin-top: 16px;
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px 0px 0px 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 18px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 30px;
      }
    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
